{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Data Types in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we know that python is Dynamically typed programming language, than why do we need to learn about data type at all?\n",
    "\n",
    "Although python automatically understands the data type, but it is important to know about data types so that we can utilize the power of data structures in future.\n",
    "\n",
    "Basic Data Types available in python are:\n",
    "<pre>\n",
    "    <b>Numeric</b> - int, float, complex (Immutable)\n",
    "    <b>Strings</b> (Immutable)\n",
    "    <b>List</b> (Mutable, mostly used to store homogeneous data types)\n",
    "    <b>Tuple</b> (Immutable, faster compared to List)\n",
    "    <b>Set</b> (Unordered collection of items, mutable, removes duplicates)\n",
    "    <b>Dictionary</b> (Unordered collection of Key-Value Pairs, Mutable, Keys are Unique - values may not be unique)\n",
    "</pre>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Strings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# c = 'a'\n",
    "\n",
    "# print(type(c))\n",
    "\n",
    "# s = 'We are leaning Python!'\n",
    "\n",
    "# print(type(s))\n",
    "\n",
    "# print(len(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# s = 'hi'\n",
    "\n",
    "# print(s[1])\n",
    "\n",
    "# # print(s[3])\n",
    "\n",
    "# # print(s[1.0])\n",
    "\n",
    "# print(s+' there')\n",
    "\n",
    "# print(s, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# s = ' We are learning Python! '\n",
    "\n",
    "# print(s.upper())\n",
    "\n",
    "# print(s.lower())\n",
    "\n",
    "# print(s.strip()) # Removes extra white spaces from front and back"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# s = 'We are leaning Python!'\n",
    "\n",
    "# print(s.find('learning'))\n",
    "\n",
    "# s = s.replace('leaning', 'learning')\n",
    "\n",
    "# print(s)\n",
    "\n",
    "# split_string = s.split(' ')\n",
    "\n",
    "# print(split_string)\n",
    "\n",
    "# print(type(split_string))\n",
    "\n",
    "# join_string = ' '.join(split_string)\n",
    "\n",
    "# print(join_string)\n",
    "\n",
    "# print(type(join_string))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# s = 'We are leaning Python!'\n",
    "\n",
    "# print(s[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# s = 'ThatAIGuy'\n",
    "\n",
    "# print(s[-9])\n",
    "\n",
    "# # print(s[::2])\n",
    "\n",
    "# # print(s[:5])\n",
    "\n",
    "# # print(s[5:])\n",
    "\n",
    "# print(s[-7:-3:1])\n",
    "\n",
    "# # print(s[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Try below mentioned methods\n",
    "\n",
    "# # isalpha(), isdigit(), isspace()\n",
    "# # startswith('abc'), endswith('abc')\n",
    "# # find('abc') returns first index, otherwise -1\n",
    "# # replace('old', 'new')\n",
    "# # split(' ') return list\n",
    "# # ' '.join(list) return string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Strings are Immutable\n",
    "\n",
    "# s = 'ThatAIguy'\n",
    "\n",
    "# print(s)\n",
    "\n",
    "# print(s[6])\n",
    "\n",
    "# s[6] = 'G'\n",
    "\n",
    "# print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# Initialization\n",
    "\n",
    "l = []\n",
    "\n",
    "print(type(l))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['shark', 'cuttlefish', 'squid', 'mantisshrimp', 'anemone']\n",
      "<class 'list'>\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "sea_creatures = ['shark', 'cuttlefish', 'squid', 'mantisshrimp', 'anemone']\n",
    "\n",
    "print(sea_creatures)\n",
    "\n",
    "print(type(sea_creatures))\n",
    "\n",
    "print(len(sea_creatures))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "shark\n",
      "cuttlefish\n",
      "squid\n",
      "mantisshrimp\n",
      "anemone\n"
     ]
    },
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-2-3bd20c3a1e17>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     11\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msea_creatures\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msea_creatures\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     14\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'*'\u001b[0m\u001b[1;33m*\u001b[0m\u001b[1;36m20\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "sea_creatures = ['shark', 'cuttlefish', 'squid', 'mantisshrimp', 'anemone']\n",
    "\n",
    "print(sea_creatures[0])\n",
    "\n",
    "print(sea_creatures[1])\n",
    "\n",
    "print(sea_creatures[2])\n",
    "\n",
    "print(sea_creatures[3])\n",
    "\n",
    "print(sea_creatures[4])\n",
    "\n",
    "print(sea_creatures[5])\n",
    "\n",
    "print('*'*20)\n",
    "\n",
    "print(sea_creatures[-1])\n",
    "\n",
    "print(sea_creatures[-2])\n",
    "\n",
    "print(sea_creatures[-3])\n",
    "\n",
    "print(sea_creatures[-4])\n",
    "\n",
    "# try print(sea_creatures[-6]) it will throw out of range error\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10, 'Hi', 20.2, True]\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "This is a multi line comment demonstrated by using triple single-quote\n",
    "\n",
    "Below mentioned list 'l' is a collection of heterogeneous data types.\n",
    "'''\n",
    "\n",
    "l = []\n",
    "\n",
    "l.append(10)\n",
    "\n",
    "l.append('Hi')\n",
    "\n",
    "l.append(20.20)\n",
    "\n",
    "l.append(True)\n",
    "\n",
    "print(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# \"\"\"\n",
    "# This is a multi line comment demonstrated by using triple double-quote\n",
    "\n",
    "# This is an example for nested lists.\n",
    "# \"\"\"\n",
    "\n",
    "# nest_list = ['Happy', [2, 0, 1, 5]]\n",
    "\n",
    "# print(nest_list[0][1])\n",
    "\n",
    "# print(nest_list[1][3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# \"\"\"\n",
    "# Because lists are mutable, below written code will\n",
    "# overwrite existing list\n",
    "# \"\"\"\n",
    "\n",
    "# sea_creatures = ['shark', 'cuttlefish', 'squid', 'mantisshrimp', 'anemone']\n",
    "\n",
    "# print(sea_creatures)\n",
    "\n",
    "# sea_creatures[1] = 'octopus'\n",
    "\n",
    "# print(sea_creatures)\n",
    "\n",
    "# sea_creatures[-3] = 'blobfish'\n",
    "\n",
    "# print(sea_creatures)\n",
    "\n",
    "# sea_creatures[0][2] = 'd'\n",
    "\n",
    "# print(sea_creatures)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Slicing Operation\n",
    "\n",
    "# my_list = ['C', 'i', 'p', 'h', 'e', 'r', 'S', 'c', 'h', 'o', 'o', 'l', 's']\n",
    "\n",
    "# print(my_list[:-5])\n",
    "\n",
    "# print(my_list[-4:-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "List before sorting: [3, 1, 2, 8, 5, 4]\n",
      "List after sorting: [1, 2, 3, 4, 5, 8]\n"
     ]
    }
   ],
   "source": [
    "#  Sorting a list\n",
    "\n",
    "l = [3, 1, 2, 8, 5, 4]\n",
    "\n",
    "print(\"List before sorting:\", l)\n",
    "\n",
    "l.sort()\n",
    "\n",
    "print(\"List after sorting:\", l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Try below mentioned Methods\n",
    "\n",
    "# append(element)\n",
    "# insert(index, element) This will insert 'element' at the given 'index'\n",
    "# list1.extend(list2) appends list2 at the end of list1\n",
    "# list.index(element) \n",
    "# list.index(element, index) find next element starting at 'index'\n",
    "# list.remove(element)\n",
    "# list.sort() here list should contain one kind of data type\n",
    "# list.reverse()\n",
    "# list.pop(index)\n",
    "# list.count(element)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![title](img/1.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "lst_1 = [1, 2, 3]\n",
    "lst_2 = [4, 5, 6]\n",
    "\n",
    "print(lst_1 + lst_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![title](img/2.jpg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tuple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "#initialization\n",
    "\n",
    "t = ()\n",
    "\n",
    "print(type(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "t = tuple()\n",
    "\n",
    "print(type(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3)\n"
     ]
    }
   ],
   "source": [
    "t = (1,2,3)\n",
    "\n",
    "print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 'Python', 1.2, 'ThatAIGuy')\n"
     ]
    }
   ],
   "source": [
    "t = (1, 'Python', 1.2, 'ThatAIGuy')\n",
    "\n",
    "print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, (1, 2, 3), [1, 2, 3])\n"
     ]
    }
   ],
   "source": [
    "t = (1, (1, 2, 3), [1, 2, 3])\n",
    "\n",
    "print(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# t = (1)\n",
    "\n",
    "# print(type(t))\n",
    "\n",
    "# t = ('ThatAIGuy')\n",
    "\n",
    "# print(type(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# t = 1,2\n",
    "\n",
    "# print(type(t))\n",
    "\n",
    "# t = 'ThatAIGuy',2\n",
    "\n",
    "# print(type(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "(2, 3)\n"
     ]
    }
   ],
   "source": [
    "# Accessing with index\n",
    "\n",
    "t = (1, 2, 3)\n",
    "\n",
    "print(t[-1])\n",
    "\n",
    "# Slicing\n",
    "\n",
    "print(t[1:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # # Tuples are Immutable\n",
    "\n",
    "# t = (1, 2, 3, (4, 5), [6, 7, 8])\n",
    "\n",
    "# t[2] = 'Hi'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# t = (1, 2, 3, 4, 5, 6, 7, 1, 2, 1, 7)\n",
    "\n",
    "# # count(element)\n",
    "# print(t.count(1))\n",
    "\n",
    "# # index(element)\n",
    "# print(t.index(7))\n",
    "\n",
    "# # len()\n",
    "# print(len(t))\n",
    "\n",
    "# # min()\n",
    "# print(min(t))\n",
    "\n",
    "# # max()\n",
    "# print(max(t))\n",
    "\n",
    "# # sum()\n",
    "# print(sum(t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # del the tuple\n",
    "# del t\n",
    "\n",
    "# print(t)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'set'>\n"
     ]
    }
   ],
   "source": [
    "# initialization\n",
    "\n",
    "s = set()\n",
    "\n",
    "print(type(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{8, 1, 4, 0}\n",
      "<class 'set'>\n"
     ]
    }
   ],
   "source": [
    "s = set([1, 4, 8, 0])\n",
    "\n",
    "print(s)\n",
    "\n",
    "print(type(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Try\n",
    "\n",
    "# s = {}\n",
    "\n",
    "# print(type(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# s = {1, 2, 3}\n",
    "\n",
    "# print(s)\n",
    "\n",
    "# print(type(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Duplicates\n",
    "\n",
    "# s = {1, 2, 3, 1, 2}\n",
    "\n",
    "# print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # try index\n",
    "\n",
    "# s = {1, 2, 3}\n",
    "\n",
    "# print(s[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 2, 3, 4, 5}\n",
      "{1, 2, 3, 4, 5}\n",
      "{3}\n",
      "{3}\n",
      "{1, 2}\n",
      "{1, 2}\n",
      "{1, 2, 4, 5}\n",
      "{1, 2, 4, 5}\n"
     ]
    }
   ],
   "source": [
    "# Set Operations\n",
    "\n",
    "set1 = {1, 2, 3}\n",
    "set2 = {3, 4, 5}\n",
    "\n",
    "print(set1 | set2)\n",
    "\n",
    "print(set1.union(set2))\n",
    "\n",
    "print(set1 & set2)\n",
    "\n",
    "print(set1.intersection(set2))\n",
    "\n",
    "print(set1 - set2)\n",
    "\n",
    "print(set1.difference(set2))\n",
    "\n",
    "print(set1 ^ set2)\n",
    "\n",
    "print(set1.symmetric_difference(set2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "# initialization\n",
    "\n",
    "d = {}\n",
    "\n",
    "print(type(d))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: 'abc', 2: 'efg', 'name': 'xyz'}\n"
     ]
    }
   ],
   "source": [
    "d = {1:'abc', 2:'efg', 'name':'xyz'}\n",
    "\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc\n",
      "xyz\n"
     ]
    }
   ],
   "source": [
    "# Accessing values\n",
    "\n",
    "print(d[1])\n",
    "\n",
    "print(d['name'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(d[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: 'abc', 2: 'efg', 'name': 'xyz'}\n",
      "{1: 'abc', 2: 'efg', 'name': 'lmn', 'age': 20}\n"
     ]
    }
   ],
   "source": [
    "# # updating dictionary\n",
    "\n",
    "print(d)\n",
    "\n",
    "d['name'] = 'lmn'\n",
    "\n",
    "d['age'] = 20\n",
    "\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1: 'abc', 2: 'efg', 'age': 20}\n",
      "{}\n"
     ]
    }
   ],
   "source": [
    "# Deleting elements\n",
    "\n",
    "del d['name']\n",
    "print(d)\n",
    "\n",
    "d.clear()\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'd' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-24-85549cb1de5f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0md\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'd' is not defined"
     ]
    }
   ],
   "source": [
    "del d\n",
    "\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # Key must immutable\n",
    "\n",
    "# d = {1:'abc', 2:'efg', ['name']:'xyz'}\n",
    "\n",
    "# print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# d.keys()\n",
    "\n",
    "# d.values()\n",
    "\n",
    "# d.items()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Mutable vs Immutable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hi\n"
     ]
    }
   ],
   "source": [
    "s = 'Hi'\n",
    "\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# s[1] = 'I'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = 4\n",
    "\n",
    "# b = 4\n",
    "\n",
    "# print(id(a))\n",
    "\n",
    "# print(id(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "# a = 5\n",
    "\n",
    "# b = 5\n",
    "\n",
    "# print(id(a))\n",
    "\n",
    "# print(id(b))\n",
    "\n",
    "# a = 6\n",
    "\n",
    "# print(id(a))\n",
    "\n",
    "# print(id(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# s = 'hi'\n",
    "# s1 = 'hi'\n",
    "\n",
    "# print(id(s))\n",
    "# print(id(s1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# lst1 = [1,2,3]\n",
    "# lst2 = [1,2,3]\n",
    "\n",
    "# print(id(lst1))\n",
    "# print(id(lst2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Summary of the session\n",
    "\n",
    "## Strings\n",
    "\n",
    "1. String is a sequence of characters.\n",
    "2. Use index to access characters in a string\n",
    "3. If we try to access index out of range or use decimal numbers we will get an error.\n",
    "4. Python supports both +ve and -ve index\n",
    "5. Strings are immutable. Elemets of strings can't be changed once it has been assigned. We can simply reassign different strings to the same name\n",
    "6. Strings support indexing as well as slicing.\n",
    "\n",
    "## Lists\n",
    "\n",
    "1. Sequence Data Structure.\n",
    "2. Used to store collection of items.\n",
    "3. Order is preserved in a list\n",
    "4. Mutable\n",
    "5. Indexing and slicing\n",
    "6. Dynamic i.e. increase or decrease in size\n",
    "\n",
    "## Tuples\n",
    "\n",
    "1. Similar to list but immutable.\n",
    "2. Sequence data type.\n",
    "3. Supports indexing and slicing.\n",
    "\n",
    "## Set\n",
    "\n",
    "1. Unordered collection of items i.e. they can't be indexed\n",
    "2. No duplicates allowed\n",
    "3. Mutable\n",
    "4. Used to perform mathematical operations like Union, intersection, etc..\n",
    "\n",
    "## Dictionary\n",
    "\n",
    "1. Unordered collection of items i.e. can't be indexed\n",
    "2. Other compound data tupes have only values as an element, whereas a dictionary has a KEY:VALUE pair\n",
    "3. Keys are unique, values may not be unique\n",
    "4. Values can be of any type, but key must be immutable."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
